import type { BaiduElements } from '../../../../../../../../types/constants'
import type { ThemeType } from '../../../../../../../../types/interfaces'
import { ThemeVarService } from '../../../../../../../../lib/abstract/style/theme_var/service'
import {
  AppStyleCollections,
  BodyAttrs,
  generateHideSelector,
  PAGE_ELEMENTS,
  SUPPORTED_PLATFORMS,
} from '../../../../../../../../types/constants'

export class BaiduIndexPage {
  elements: BaiduElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.BAI_DU]
  private static instance: BaiduIndexPage
  private readonly themeVarService: ThemeVarService = ThemeVarService.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): BaiduIndexPage {
    if (!BaiduIndexPage.instance) {
      BaiduIndexPage.instance = new BaiduIndexPage()
    }
    return BaiduIndexPage.instance
  }

  init(): void {
  }

  getMainStyles(_theme: ThemeType): string {
    return `
  overflow: hidden !important;
  
  /* 有壁纸时背景颜色置为透明 */
  &.${AppStyleCollections.Wallpaper.EXISTS} #wrapper {
    #head {
      background-color: transparent !important;
      
      #bottom_layer {
        background-color: transparent !important;
      }
    }
    
    #head:has(#s-top-left.${AppStyleCollections.Hide.AD}, #s-top-left[${BodyAttrs.HIDE_TYPE}]):has(#u1.${AppStyleCollections.Hide.AD}, #u1[${BodyAttrs.HIDE_TYPE}]) {
      #s_top_wrap {
        background-color: transparent !important;
      }
    }
  }
  
  #wrapper {
    height: 100vh !important;
    
    /* 隐藏样式 */
    #head:has(${generateHideSelector('#s-top-left')}):has(${generateHideSelector('#u1')}) {
      #s_top_wrap {
        background: transparent !important;
      }
    }
    #head:has(${generateHideSelector('#u1')}) {
      #s-top-left {
        position: relative !important;
        text-align: center !important;
        padding: 0 !important;
      }
    }
    
    .fixed-skin-wrapper {
      background: transparent !important;
    }

    #head {
      background-color: transparent !important;
      
      #s_top_wrap {
        background: var(${this.themeVarService.search.header.background}) !important;
      }
      
      #s-top-left {
        > a, .s-top-more-btn > a {
          color: var(${this.themeVarService.search.default.text}) !important;
          
          &:hover {
            color: var(${this.themeVarService.link.default.text}) !important;
          }
        }
      }
      
      #u1 {
        > span, > a {
          color: var(${this.themeVarService.search.default.text}) !important;
          
          &:hover {
            color: var(${this.themeVarService.link.default.text}) !important;
          }
        }
        
        #s-top-loginbtn {
          color: white !important;
        }
      }
      
      #head_wrapper {
        #main-wrapper {
          .chat-input-wrapper-box-shadow, .chat-input-wrapper {
            box-shadow: none !important;
          }
        }

        #s-hotsearch-wrapper {
          ul li a {
            color: var(${this.themeVarService.search.default.text}) !important;
            
            &:hover {
              color: var(${this.themeVarService.link.default.textHover}) !important;
              text-decoration: none !important;
            }
          }
        }
      }
      
      #bottom_layer {
        background: transparent !important;
        
        a {
          color: var(${this.themeVarService.link.default.text}) !important;
          
          &:hover {
            color: var(${this.themeVarService.link.default.textHover}) !important;
          }
        }
      }
    }
  }
`
  }
}
